<%--
  Created by IntelliJ IDEA.
  User: tjs
  Date: 2021/7/19
  Time: 18:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        body {
            background-image: url("${pageContext.request.contextPath}/static/imgs/back2.jpg");
            background-size: 100%;


        }
        #divOne{
            width: 600px;
            height: 400px;
            margin: 100px auto;
            border: #bee5eb solid 2px;
            background: ghostwhite;
            opacity: 0.8;
            border-radius: 5%;

        }
        .divTwo{
            width: 400px;
            margin: 20px auto;
        }
        .tm{
            opacity: 0.8;
        }


    </style>
</head>
<body>
<%
    String path = request.getContextPath();
%>
<%--<jsp:include page="../common/css_js.jsp"/>--%>
<%--<jsp:include page="${pageContext.request.contextPath}/common/css_js.jsp"/>--%>
<link href="<%=path%>/static/bootstrap4.6.0/css/bootstrap.css" rel="stylesheet">
<script src="<%=path%>/static/jq/jquery-3.6.0.js"></script><!--bootstrap依赖于js所以要先导入-->
<script src="${pageContext.request.contextPath}/static/bootstrap4.6.0/js/bootstrap.bundle.js"></script>
<div id="divOne">
    <div class="container">
        <h3 class="mt-3 mt-b text-center">用户登录页面</h3>
        <%--    <div style="text-align: center">--%>
        <%--        <img src="${pageContext.request.contextPath}/static/imgs/1.webp" width="80" style="border-radius: 50%">--%>
        <%--    </div>--%>
        <form action="user/zuChe" method="get" id="form">
            <div class="form-group divTwo">
                <label for="name">用户名</label>
                <input type="text" name="username" id="name" placeholder="请输入用户名" class="form-control">
                <div id="nameInfo" class="text-danger" style="display: none">用户名必须4到20位</div>
            </div>
            <div class="form-group divTwo">
                <label for="names">密码</label>
                <input type="password" name="password" id="names" placeholder="请输入密码" class="form-control">
                <div id="passwordInfo" class="text-danger" style="display: none">密码需要3位以上</div>
            </div>
            <div class="form-group divTwo">
                <input type="text" name="password" style="width:40%; float: left" id="yzm" placeholder="请输入验证码" class="form-control tm">
                <img id="img" style="float: left" src="user/login">
                <input id="btn" type="button" class="btn btn-success" value="看不清,换一张">
            </div>


            <div class="divTwo" style="margin-top: 20px">
                <a href="register.jsp">
                    <button type="button" class="btn btn-success">注册</button>
                </a>
                <a href="forget.jsp">
                    <button type="button" class="btn btn-success">忘记密码</button>
                </a>
                <button type="button" onclick="loginshowUser()" class="btn btn-success">用户登录</button>
            </div>
        </form>
    </div>
</div>

<script>
    function loginshowManager() {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/shirologinUser",
            type: "get",
            data: {
                username: $("#name").val(),
                password: $("#names").val(),
                yzm: $("#yzm").val()
            },
            success: function (data) {
                if (data["code"] == 0) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";

                }
                if (data["code"] == 1) {
                    alert("验证码为错误");
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 2) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 3) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 5) {
                    alert("登陆成功");
                    location.href = "${pageContext.request.contextPath}/goods/getAllByPage"
                }
            }

        })
    }
</script>
<script>
    function loginshowUser() {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/shirologinUser",
            type: "get",
            data: {
                username: $("#name").val(),
                password: $("#names").val(),
                yzm: $("#yzm").val()
            },
            success: function (data) {
                if (data["code"] == 0) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";

                }
                if (data["code"] == 1) {
                    alert("验证码为错误");
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 2) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 3) {
                    alert(data["message"]);
                    location.href = "<%=path%>/login.jsp";
                }
                if (data["code"] == 5) {
                    alert("登录成功");

                    <%--var i = data["loginUser"].userNick;--%>
                    <%--location.href="${pageContext.request.contextPath}/goods/getAllByPage?userNick="+i;--%>
                    location.href = "${pageContext.request.contextPath}/goods/getAllByPage";
                }
            }

        })
    }
</script>


<script>
    function loginManager() {
        $.ajax({
            url: "${pageContext.request.contextPath}/user/loginManager",
            type: "get",
            data: {
                username: $("#name").val(),
                password: $("#names").val(),
                yzm: $("#yzm").val()
            },
            success: function (data) {
                if (data == "1") {
                    alert("验证码为空");
                    location.href = "${pageContext.request.contextPath}/login.jsp";

                }
                if (data == "ok") {
                    alert("验证码错误");
                    location.href = "${pageContext.request.contextPath}/login.jsp";

                }
                if (data == "error") {
                    alert("用户不存在，账号或密码错误请重新登录");
                    location.href = "${pageContext.request.contextPath}/login.jsp";
                }
                if (data == "success") {
                    alert("恭喜你登录成功")
                    location.href = "${pageContext.request.contextPath}/Managersuccess.jsp";
                }

            },
            error: function (data) {


            }
        })


    }
</script>

<script>
    window.onload = function () {
        document.getElementById("btn").onclick = function () {
            var a = document.getElementById("img");
            a.src = "user/login?time=" + new Date().getTime();

        }

    }
</script>


<%--<script>--%>
<%--    function check() {--%>
<%--        if($("#name").val().length<3 || $("#name").val().length>20 ){--%>
<%--            alert("你输入的账号不合法");--%>
<%--            return false;--%>
<%--        }--%>
<%--        if($("#names").val().length<3 || $("#names").val().length>20){--%>
<%--            alert("你输入的密码不合法");--%>
<%--            return false--%>
<%--        }--%>

<%--    }--%>
<%--    function checkname() {--%>
<%--        if($("#name").val().length<3 || $("#name").val().length>20 ){--%>
<%--            $("#nameInfo").show();--%>
<%--        }else {--%>
<%--            $("#nameInfo").hide();--%>
<%--            $.ajax({--%>
<%--                url:"<%=path%>/user/util",--%>
<%--                data:{--%>
<%--                    action:"isUserExist",--%>
<%--                    name:$("#name").val()--%>
<%--                },--%>
<%--                success:function (data) {--%>
<%--                    if("yes"==data){--%>

<%--                    }else {--%>
<%--                        alert("你输入的用户不存在")--%>
<%--                    }--%>

<%--                }--%>
<%--            })--%>
<%--        }--%>
<%--    }--%>
<%--    function checkpassword() {--%>
<%--        if($("#names").val().length<3 || $("#names").val().length>20 ){--%>
<%--            $("#passwordInfo").show();--%>
<%--        }else {--%>
<%--            $("#passwordInfo").hide();--%>
<%--        }--%>
<%--    }--%>

<%--</script>--%>
<%--&lt;%&ndash;防止表单提交黑客&ndash;%&gt;--%>
<%--<div id="info">${param.info}</div>--%>
<%--<script>--%>
<%--    if ($("#info").text().length>0){--%>
<%--        alert($("#info").text());--%>
<%--    }--%>
<%--</script>--%>
</body>
</html>
